<template>
	<view class="">
		<search @click.native="gotoSearch" ></search>
		<view class="scroll-view-container">
			<!-- 左侧一级导航 -->
			<scroll-view scroll-y="true" class="left-scroll-view" :style="{height:wh+'px'}">
				<view class="left-scroll-view-item" :class="{active:active===index}" v-for="(item,index) in cateList"
					:key="item.cat_id" @click="changeFriNav(index)">{{item.cat_name}}</view>
			</scroll-view>
			<!-- 右侧二三级导航 -->
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="right-scroll-view" :style="{height: wh + 'px'}">
				<view class="box" v-for="(it,i) in children" :key="it.cat_id">
					<view class="box_title">
						{{it.cat_name}}
					</view>
					<view class="smallBox">
						<navigator :url="'/pkgGoods/goods_list/goods_list?cat_id='+it3.cat_id" class="smallBox_item" v-for="(it3,i3) in children[i].children" :key="it3.cat_id">
							<image :src="it3.cat_icon" mode=""></image>
							<text>{{it3.cat_name}}</text>
						</navigator>
					</view>
				</view>
		
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cateList: [],
				// 一级导航，高亮的索引
				active: 0,
				// 可视区域的高度
				wh: 0,
				// 二级导航的列表
				children: [],
				// 滚动条位置
				scrollTop:0
			};
		},
		async onLoad() {
			this.getCateList()
			// 获取设备可视区域的高度
			this.wh = await uni.getWindowInfo().windowHeight-50
		},
		methods: {
			// 请求分类列表
			async getCateList() {
				const {
					data: res
				} = await uni.$http.get('/categories')
				if (res.meta.status !== 200) return uni.$showMsg()
				this.cateList = res.message
				this.children = res.message[this.active].children
			},
			// 点击一级导航
			changeFriNav(index) {
				this.active = index
				this.children = this.cateList[index].children
				this.scrollTop=0
			},
			// 跳转到搜索也
			gotoSearch(){
				uni.navigateTo({
					// url:'/pkgGoods/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	.scroll-view-container {
		display: flex;

		.left-scroll-view {
			width: 120px;

			.left-scroll-view-item {
				line-height: 60px;
				background-color: #f7f7f7;
				text-align: center;
				font-size: 12px;

				// 激活项的样式
				&.active {
					background-color: #ffffff;
					position: relative;

					// 渲染激活项左侧的红色指示边线
					&::before {
						content: ' ';
						display: block;
						width: 3px;
						height: 30px;
						background-color: #c00000;
						position: absolute;
						left: 0;
						top: 50%;
						transform: translateY(-50%);
					}
				}
			}
		}

		.right-scroll-view {
			background-color: #ffffff;
			.box {
				.box_title {
					font-size: 16px;
					font-weight: bold;
					text-align: center;
					padding: 15px 0;
				}
				.smallBox {
					display: flex;
					flex-wrap: wrap;
					.smallBox_item{
						width: 33.33%;
						margin-bottom: 10px;
						display: flex;
						flex-direction: column;
						align-items: center;
						image {
						      width: 60px;
						      height: 60px;
						    }
						
						    text {
						      font-size: 12px;
						    }
					}
				}
			}
		}
	}
</style>
